//
//  CWBaseView.h
//  CWDevelop
//
//  Created by LittoCats on 7/11/14.
//  Copyright (c) 2014 Littocats. All rights reserved.
//

#import <UIKit/UIKit.h>

//定义自动布局中view的边距
typedef struct CWRim {
    CGFloat top, bottom, left, right;
} CWRim;

struct CWRim CWRimMake(CGFloat top, CGFloat bottom, CGFloat left, CGFloat right);

typedef struct CWRim CWMargin;
#define CWMarginMake(...) CWRimMake(__VA_ARGS__)
#define CWMarginZero CWMarginMake(0,0,0,0)

typedef struct CWRim CWPadding;
#define CWPaddingMake(...) CWRimMake(__VA_ARGS__)
#define CWPaddingZero CWMarginMake(0,0,0,0)

#define CWAutoLayoutAlignTopValueOfset      12
#define CWAutoLayoutAlignBottomValueOfset   (CWAutoLayoutAlignTopValueOfset +1)
#define CWAutoLayoutAlignLeftValueOfset     (CWAutoLayoutAlignTopValueOfset +2)
#define CWAutoLayoutAlignRightValueOfset    (CWAutoLayoutAlignTopValueOfset +3)
typedef NS_ENUM(NSInteger, CWAutoLayoutAlign) {
    CWAutoLayoutAlignTop        = 1 << CWAutoLayoutAlignTopValueOfset,
    CWAutoLayoutAlignBottom     = 1 << CWAutoLayoutAlignBottomValueOfset,
    CWAutoLayoutAlignLeft       = 1 << CWAutoLayoutAlignLeftValueOfset,
    CWAutoLayoutAlignRight      = 1 << CWAutoLayoutAlignRightValueOfset
};

CWAutoLayoutAlign anaylzeCWAutoLayoutAlign(NSString *script);

@interface UIView (CWCustomAttributes)
/**
 *  自定义属性的容器
 */
@property (nonatomic, readonly) NSMutableDictionary *attributes;

/**
 *  margin
 */
@property (nonatomic) CWMargin margin;

/**
 *  padding
 */
@property (nonatomic) CWPadding padding;

/**
 *  algin
 */
@property (nonatomic) CWAutoLayoutAlign align;

/**
 *  size
 */
@property (nonatomic) CGSize size;

@end

@interface UIView (CWUIJSONView)

/**
 *  根据 JSONLayout 生成 UIView 对像
 */
+ (instancetype)instanceWithJSONLayout:(NSDictionary *)JSONLayout;

@end


@interface CWViewGeneralAttributesSetter : NSObject

#define CWViewGeneralAttributeSetter(attribute, instanceProcessor, selector, paramsProcessor) \
    +(void)instance:(id)instance attribute:(id)params\
    {\
        if ([instanceProcessor respondsToSelector:selector])\
            objc_msgSend(instanceProcessor, selector,paramsProcessor);\
    }

+ (void)setGeneralAttributes:(NSDictionary *)attributesMap ofCWView:(id)view;
@end

@interface CWViewGeneralAttributesGetter : NSObject
#define CWViewGeneralAttributeGetterResult_id objc_msgSend(instance, attributeSelector)
#define CWViewGeneralAttributeGetterResult_float objc_msgSend_fpret(instance, attributeSelector)

#define CWViewGeneralAttributeGetter(attribute, selector, getterProcessor) \
+(id)attribute:(void *)params ofInstance:(id)instance \
{\
    SEL attributeSelector = selector;\
    if ([instance respondsToSelector:attributeSelector])\
       return getterProcessor;\
    return nil;\
}

+ (id)getGeneralAttributes:(NSString *)attribute ofCWView:(id)view;
@end

//overlay 管理
@interface UIView (CWUIViewOverlay)

@property (nonatomic, readonly) NSArray *overlays;

- (void)addOverlay:(UIView *)overlay;
@end


//baseview
@interface CWBaseView : UIView

@end
